package com.estock.platform.task.support;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class BaseQueue<T> {

	private static Object instanceLock = new Object();
	@SuppressWarnings("rawtypes")
	private static BaseQueue instance;

	private BlockingQueue<T> queue;
	private static final int QUEUE_SIZE = 50;

	private BaseQueue() {
		queue = new LinkedBlockingQueue<T>(QUEUE_SIZE);
	}

	@SuppressWarnings("unchecked")
	public static <T> BaseQueue<T> getInstance() {
		synchronized (instanceLock) {
			if (instance == null)
				instance = new BaseQueue<T>();
			return instance;
		}
	}

	public void push(T task) {
		try {
			queue.put(task);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public T pop() {
		try {
			return queue.take();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return null;
	}

	public BlockingQueue<T> getQueue() {
		return queue;
	}
	
}
